package com.xyazm.order.enums;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.Getter;

import java.util.HashMap;
import java.util.Map;

/**
 * 订单号类型枚举
 */
@Getter
public enum OrderNoTypeEnum {

    /**
     * 正向订单
    */
    ORDER_SALE(10, "order_sale"),

    /**
     * 售后订单
    */
    AFTER_SALE(20, "after_sale");


    private Integer code;

    private String msg;

    OrderNoTypeEnum(Integer code, String msg) {
        this.code = code;
        this.msg = msg;
    }

    public static Map<Integer,String> toMap(){
        Map<Integer,String> map = new HashMap<>(16);
        for (OrderNoTypeEnum element : OrderNoTypeEnum.values() ){
            map.put(element.getCode(),element.getMsg());
        }
        return map;
    }

    /**
     * 根据枚举code获取枚举
     * @author xuyou
     * 2022/4/10 0010 20:26
     * @param code
     * @return 订单号类型枚举
    */
    public static OrderNoTypeEnum getByCode(Integer code){
        for(OrderNoTypeEnum element : OrderNoTypeEnum.values()){
            if (code.equals(element.getCode())) {
                return element;
            }
        }
        return null;
    }

}
